package com.huang.core.widget.viewpager.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import android.view.ViewGroup
import java.util.*


class LoopViewPagerAdapter(
        fm: FragmentManager,
        val mTitles: Array<String>? = null,
        val mFragments: ArrayList<Fragment>
) : FragmentPagerAdapter(fm) {

    override fun getItem(position: Int): Fragment {
        return mFragments[position]
    }

    override fun getPageTitle(position: Int): CharSequence {
        if (mTitles == null) return ""
        return mTitles[position]
    }

    override fun getCount(): Int {
        return Integer.MAX_VALUE
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        super.destroyItem(container, position, `object`)
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        return super.instantiateItem(container, position % mFragments.size)
    }
}